package br.home.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import br.home.entitys.Garcom;
import br.home.jdbc.ConnectionFactory;

public class GarcomDao {

	public static Garcom selectOne(int idgarcom) {
		Garcom garcom;
		try {
			garcom = null;
			Connection con = ConnectionFactory.getConnection();
			String sql = "SELECT * FROM garcom WHERE idgarcom = ? LIMIT 1";
			PreparedStatement stmt = con.prepareStatement(sql);
			stmt.setInt(1, idgarcom);
			ResultSet result = stmt.executeQuery();
			while (result.next()) {
				garcom = new Garcom();
				garcom.setId(result.getInt("idgarcom"));
				garcom.setNome(result.getString("nome"));
				garcom.setTelefone(result.getString("telefone"));
				garcom.setAtivo(result.getBoolean("ativo"));
			}
			if (garcom != null) {
				return garcom;
			} else {
				return null;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

}
